//
//  LBTabBarViewController.m
//  01.SinaBlog
//
//  Created by Label on 12/13/15.
//  Copyright © 2015 Label. All rights reserved.
//

#import "LBTabBarViewController.h"

#import "LBNavigationController.h"
#import "LBHomeViewController.h"
#import "LBMessageTableViewController.h"
#import "LBDiscoverTableViewController.h"
#import "LBMineTableViewController.h"


@interface LBTabBarViewController ()

@end

@implementation LBTabBarViewController

/** View Did Load;
 */
- (void)viewDidLoad {
    // 1. Parent Class View Did Load;
    [super viewDidLoad];
    // 2.Add Child View Controller;
    LBHomeViewController *homeVC = [[LBHomeViewController alloc] init];
    [self addChildViewController:homeVC WithTitle:@"首页" Image:@"tabbar_home" SelectedImage:@"tabbar_home_selected"];
    
    LBMessageTableViewController *messageVC = [[LBMessageTableViewController alloc] init];
    [self addChildViewController:messageVC WithTitle:@"消息" Image:@"tabbar_message_center" SelectedImage:@"tabbar_message_center_selected"];
    
    LBDiscoverTableViewController *discoverVC = [[LBDiscoverTableViewController alloc] init];
    [self addChildViewController:discoverVC WithTitle:@"发现" Image:@"tabbar_discover" SelectedImage:@"tabbar_discover_selected"];
    
    LBMineTableViewController *mineVC = [[LBMineTableViewController alloc] init];
    [self addChildViewController:mineVC WithTitle:@"我" Image:@"tabbar_profile" SelectedImage:@"tabbar_profile_selected"];
    
}


/** Add Child View Controller;
 */
- (void)addChildViewController:(UIViewController *)viewController WithTitle:(NSString *)title Image:(NSString *)image SelectedImage:(NSString *)selectedImage {
    // 1. Set View Background Color;
 
    // 2. Set TabBarItem Title, Is Equal: [viewController setTitle:title];
    [viewController.tabBarItem setTitle:title];
    [viewController.navigationItem setTitle:title];
    NSMutableDictionary *textAttrsSelected = [NSMutableDictionary dictionary];
    textAttrsSelected[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [viewController.tabBarItem setTitleTextAttributes:textAttrsSelected forState:UIControlStateSelected];
    // 3. Set TabBarItem Image
    [viewController.tabBarItem setImage:[UIImage imageNamed:image]];
    [viewController.tabBarItem setSelectedImage:[[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    // 4. Create Navigation View Controller;
    LBNavigationController *navgationVC = [[LBNavigationController alloc] init];
    [navgationVC addChildViewController:viewController];
    // 5. Add Child View Controller;
    [self addChildViewController:navgationVC];
}

@end
